package com.xmg.p2p.base.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xmg.p2p.base.domain.Iplog;
import com.xmg.p2p.base.mapper.IplogMapper;
import com.xmg.p2p.base.query.IplogQueryObject;
import com.xmg.p2p.base.service.IplogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @BelongsProject: jinrong-website
 * @BelongsPackage: com.xmg.p2p.base.service.impl
 * @author: Andy
 * @date: 2020.12.9 18:29
 * @Description: 日志的业务实现子类
 * @since JDK 1.8
 */
@Service
public class IplogServiceimpl implements IplogService {
    @Autowired
    private IplogMapper iplogMapper; //自动加载
    public int insert(Iplog record) {
        return iplogMapper.insert(record);
    }

    public List<Iplog> selectAll(IplogQueryObject qo) {
        return iplogMapper.selectAll(qo);
    }

    public PageInfo query(IplogQueryObject qo) {
        /*查数据库道理有没日记记录*/
        int count = this.iplogMapper.queryForCount(qo);//select count(*) from xxx;

        PageInfo<Iplog> page = null;

        /*如果有在进行查询,并将查询结果封装到PageInfo对象中*/
        if (count > 0) {
            //1.使用PageHelper类中静态方法,设置当前页,和每页显示的记录数
            PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
            //2.执行对应的查询方法,这个方法会自动的添加上分页操作
            List<Iplog> iplogs = iplogMapper.selectAll(qo);
            //3.将获取的分页查询的结果进行封装,封装到PageInfo类中
            //PageInfo这个类,提供了各种获取分页信息的属性
            page = new PageInfo<Iplog>(iplogs);
        }
        return page;
    }
}
